package com.lg.partition41;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/3/2 22:05
 */
public class P4017最大食物链计数 {

    private static final int N = 5010, M = 500010, MOD = 80112002;
    private static int[] h = new int[N], e = new int[M], ne = new int[M], din = new int[N], dout = new int[N];
    private static int[] f = new int[N], q = new int[N];
    private static int n, m, idx = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        Arrays.fill(h, -1);
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            add(b, a);
            din[a]++;
            dout[b]++;
        }
        writer.write(toposort() + "\n");
        writer.flush();
    }

    private static int toposort() {
        int hh = 0, tt = 0, ans = 0;
        //将入度为0的节点加入到队列
        for (int i = 1; i <= n; i++) {
            if (din[i] == 0) {
                q[++tt] = i;
                f[i] = 1;
            }
        }
        while (hh <= tt) {
            int u = q[hh++];
            for (int i = h[u]; i != -1; i = ne[i]) {
                int v = e[i];
                f[v] = (f[v] + f[u]) % MOD;
                din[v]--;
                if (din[v] == 0) {
                    q[++tt] = v;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            if (dout[i] == 0) ans = (ans + f[i]) % MOD;
        }
        return ans;
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}
